import {defineStore} from 'pinia'

const useStore = defineStore('main', {
  state: () => {
    return {
      musicId: '',
      isPlay: false,
      musicList: [],
      musicListId: '',
      isLogin: false,
      //当前播放音乐索引
      currentIndex: -1,
      // 音乐当前播放时间
      currentTime: 0,
      //   音乐详情卡片
      isMusicDetailCardShow: false,
    //   音乐是否加载中
      isMuscLoad:false,
    }
  },
  actions: {
    // 更新音乐url
    updateMusicId(musicId) {
      this.musicId = musicId
    },
    // 修改播放状态
    changePlayState(isPlay) {
      this.isPlay = isPlay
    },
    //更新歌单列表和歌单id
    updateMuiscList(payload) {
      // 当歌单id发生变化时，重置当前音乐播放索引
      if (payload.musicListId != this.musicListId) {
        this.musicListId = payload.musicListId
        this.currentIndex = -1
      }
      let musicList = payload.musicList.slice(0)
      this.musicList = musicList
    },
    // 当前播放索引
    updateCurrentIndex(index) {
      this.currentIndex = index
    },
    // 更新当前播放时间位置
    updataCurrentTime(time) {
      this.currentTime = time
    },
    // 更改登录状态
    updateLoginState(state) {
      this.isLogin = state
    },
    
    //更改音乐卡片显示与隐藏
    changeMusicDetailCardState(){
        this.isMusicDetailCardShow = !this.isMusicDetailCardShow
    }
  },
})

 export default useStore
